package de.tabuma.ssoclient.logik;

import java.util.*;
import de.tabuma.lib.webservice.client.*;
import de.tabuma.ssoclient.entity.*;

/**
 *
 * @author alefen
 */
public class ProjectFacade {
    public static String soapUrl = "https://tabumasso.appspot.com/webservice";
    public static int create(Project project, String ssoId) throws Exception {
        String methodName = "ProjectService_create";
        String soapAction = "ProjectService_create";

        Class returnType = Integer.class;
        Object params[] = {project, ssoId};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        project.setId(obj.longValue());
        ProjectHashFacade.put(project, ssoId);
        return obj;
    }

    public static void update(Project project, String ssoId) throws Exception {
        String methodName = "ProjectService_update";
        String soapAction = "ProjectService_update";

        Object params[] = {project, ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        ProjectHashFacade.put(project, ssoId);
    }

    public static Project get(int id, String ssoId) throws Exception {
        String methodName = "ProjectService_get";
        String soapAction = "ProjectService_get";

        Class returnType = Project.class;
        Object params[] = {Integer.valueOf(id), ssoId};

        Project obj = ProjectHashFacade.get(id, ssoId);
        if(obj==null) {
            obj = (Project) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        }
        return obj;
    }

    public static void remove(int id, String ssoId) throws Exception {
        String methodName = "ProjectService_remove";
        String soapAction = "ProjectService_remove";

        Object params[] = {Integer.valueOf(id), ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        ProjectHashFacade.remove(id, ssoId);
    }

    public static List<Project> getList(int customerId, String ssoId) throws Exception {
        String methodName = "ProjectService_getList";
        String soapAction = "ProjectService_getList";

        Class returnType = List.class;
        Class returnType1 = Project.class;
        Object params[] = {Integer.valueOf(customerId), ssoId};

        List<Project> obj = ProjectHashFacade.getList(customerId, ssoId);
        if(obj==null) {
            obj = (List<Project>) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, returnType1);
            ProjectHashFacade.setList(obj, customerId, ssoId);
        }
        return obj;
    }
}
